<!-- 报告单元(rm-ddl-rptunit)，报告项目(rm-ddl-rptitem)，项目分类(rm-ddl-rptitemclass)，标本类型(rm-ddl-specimen) -->
<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div style="width:100%;">
              <el-scrollbar style="width:100%;height:100%">
                  <div ref="buttondiv">
                      <vxe-toolbar class="table1style">
                          <template v-slot:buttons>
                              <table>
                                  <tr>
                                      <td>分单类别</td>
                                      <td>
                                          <rm-ddl-common :dataname="groupname" :datatype="grouptype" @change="all_selectChange_event($event,'el_group')" appendtobody style="width:200px" v-model="reqgroup_model"></rm-ddl-common>
                                      </td>
                                      <!-- <td>开单画面</td>
                                      <td>
                                          <rm-ddl-rptunit prgno="LIS113" @change="all_selectChange_event($event,'el_unit')" appendtobody ref="select_rptunit_controls" style="width:200px" v-model="rptunit_model"></rm-ddl-rptunit>
                                      </td>
                                      <td>
                                          <el-checkbox v-model="show_right" @change="col_show_hide">仅按照开单画面项目</el-checkbox>
                                      </td>
                                      <td>
                                          <el-checkbox v-model="show_remind" @change="col_del_remind">按收费项目更新申请项目价格</el-checkbox>
                                      </td> -->
                                      <td :width="buttonwidth"></td>
                                      <td>
                                          <el-button @click="all_clear" icon="el-icon-circle-close" size="small">清空</el-button>
                                      </td>
                                  </tr>
                              </table>
                          </template>
                      </vxe-toolbar>
                  </div>
              </el-scrollbar>
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-left splitcolor="white" movingcolor="#00ff00" :splitwidth=5 :fixsize=500>
              <template v-slot:fix>
                  <div>
                      <div style="border: solid 1px #ccc;padding:3px;text-align:left;">
                          <el-input placeholder="申请项目代码|名称|输入码" prefix-icon="el-icon-search" size="small" style="max-width:200px;" v-model="item_dict_seachKey" @keyup.enter.native="item_dict_refresh"></el-input>
                          <el-button @click="item_dict_refresh" icon="el-icon-search" type="primary">查询</el-button>
                      </div>
                      <div class="child_bottom">
                          <vxe-table :data.sync="item_dict_tableData" :loading="item_dict_loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" :edit-config="{showIcon: false,activeMethod:cellactiveMethod}" header-align="center" @cell-dblclick="showDurationFinishReport" @current-change="item_dict_currentChangeEvent" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="item_dict_Table" resizable row-id="item_dict_Table_rowid" show-overflow size="mini" :row-class-name="item_dict_rowclassname" stripe>
                              <vxe-table-column field="req_groupname" sortable title="分单类别" width="70"></vxe-table-column>
                              <vxe-table-column field="req_itemcode" sortable title="项目代码" width="78"></vxe-table-column>
                              <vxe-table-column field="req_itemname" sortable title="项目名称" width="170"></vxe-table-column>
                              <vxe-table-column field="item_price" sortable title="单价" width="50" header-align="center" align="right"></vxe-table-column>
                              <vxe-table-column field="specimen_code" sortable title="默认标本类型" width="90"></vxe-table-column>
                              <vxe-table-column field="cp_div" sortable title="拆分" width="40">
                              </vxe-table-column>
                              <vxe-table-column field="cp_add" sortable title="附加" width="40">
                              </vxe-table-column>
                              <vxe-table-column field="perform_dept" sortable title="执行科室" width="80"></vxe-table-column>
                              <vxe-table-column field="inputcode" sortable title="拼音码" width="80"></vxe-table-column>
                              <vxe-table-column field="itemclasscode" sortable title="项目归类" width="80"></vxe-table-column>
                              <vxe-table-column field="hospcode" sortable title="所属院区" width="100" :edit-render="{name:'select',options: HospitalOptions}"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </div>
              </template>
              <rm-layout-right splitcolor="white" movingcolor="#0000ff" :splitwidth=5 :fixsize=middle_center :key="pagekey">
                  <template v-slot:fix>
                      <div>
                          <div style="border: solid 1px #ccc;padding:3px;">
                              <el-input placeholder="收费项目代码|名称|缩写|输入码" prefix-icon="el-icon-search" size="small" style="max-width:200px;" v-model="feeitem_seachKey" @keyup.enter.native="feeitem_refresh"></el-input>
                              <el-button @click="feeitem_refresh" icon="el-icon-search" type="primary">查询</el-button>
                          </div>
                          <div class="child_bottom">
                              <vxe-table :data.sync="feeitem_tableData" :loading="feeitem_loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" @cell-dblclick="feeitem_add_Eevent" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow header-align="center" ref="feeitem_Table" resizable row-id="feeitem_Table_rowid" show-overflow size="mini" stripe>
                                  <vxe-table-column field="feeitemcode" title="收费项目代码" width="130" sortable>
                                  </vxe-table-column>
                                  <vxe-table-column field="feeitemname" title="收费项目名称" width="200" sortable>
                                  </vxe-table-column>
                                  <vxe-table-column field="perform_dept" title="执行科室" width="150" sortable>
                                  </vxe-table-column>
                                  <vxe-table-column field="item_price" title="价格" width="100" sortable align="center"></vxe-table-column>
                                  <vxe-table-column field="inputcode" title="拼音码" width="100" sortable></vxe-table-column>
                                  <vxe-table-column field="his_class" title="HIS项目类别" width="100" sortable></vxe-table-column>
                                  <vxe-table-column field="his_itemcode" title="HIS对应项目代码" width="100" sortable></vxe-table-column>
                                  <vxe-table-column field="begindate" title="启用时间" width="175" sortable>
                                      <!-- <template v-slot="{ row }">
                                          <el-date-picker v-model="row.begindate" type="date" placeholder="启用时间" value-format="yyyy-MM-dd" clearable style="width:175px"></el-date-picker>
                                      </template> -->
                                  </vxe-table-column>
                                  <vxe-table-column field="enddate" title="停用时间" width="175" sortable>
                                      <!-- <template v-slot="{ row }">
                                          <el-date-picker v-model="row.enddate" type="date" placeholder="停用时间" value-format="yyyy-MM-dd" clearable style="width:175px"></el-date-picker>
                                      </template> -->
                                  </vxe-table-column>
                                  <vxe-table-column align="center" field="useflag" sortable title="有效" width="90">
                                  </vxe-table-column>
                              </vxe-table>
                          </div>
                      </div>
                  </template>

                  <div style="height:100%;width:100%;">
                      <div style="border: solid 1px #ccc;padding:3px;">
                          <el-scrollbar style="width:100%;height:100%">
                              <vxe-toolbar :refresh="{query: reqitem_feeitem_refresh}" style="minWidth:435px;">
                                  <template v-slot:buttons>
                                      <el-button @click="item_dict_syncdata()" style="margin-right:2px">同步HIS</el-button>
                                      <el-button @click="reqitem_feeitem_SaveEvent()" :disabled="reqitem_feeitem_saveBtnbool" style="margin-right:2px">保存数量</el-button>
                                      <el-button-group>
                                          <!-- <el-button @click="Copy()" style="margin-right:2px">同步</el-button> -->
                                          <!-- <el-button @click="Stick()" style="margin-right:2px">粘贴</el-button> -->
                                      </el-button-group>
                                      <span>金额：{{sumprice}}</span>
                                  </template>
                              </vxe-toolbar>
                          </el-scrollbar>
                      </div>
                      <div class="child_bottom">
                          <vxe-table :data.sync="reqitem_feeitem_tableData" :loading="reqitem_feeitem_loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="reqitem_feeitem_table" resizable row-id="his_interface_table_rowid" show-overflow size="mini" stripe :edit-config="{trigger: 'click', mode: 'cell',showStatus:true,showIcon:false}" header-align="center" @cell-dblclick="reqitem_feeitem_dblclick" :row-class-name="rpt_req_rowclassname" show-header-overflow :optimization="{animat: false}">
                              <vxe-table-column type="index" width="34" title="NO." align="center"></vxe-table-column>
                              <vxe-table-column field="feeitemname" sortable title="收费项目" width="120"></vxe-table-column>
                              <vxe-table-column field="item_price" sortable title="单价" width="40" align="center"></vxe-table-column>
                              <vxe-table-column align="center" field="qty" sortable title="数量" width="40" :edit-render="{name:'input',autoselect: true}">
                              </vxe-table-column>
                              <vxe-table-column align="center" field="synctime" sortable title="同步/对照时间" width="140">
                              </vxe-table-column>
                              <vxe-table-column field="req_itemname" sortable title="申请项目" width="120">
                              </vxe-table-column>
                              <vxe-table-column field="seq" sortable title="序号" width="120">
                              </vxe-table-column>
                              <!-- <vxe-table-column field="externalcode3" sortable title="对照ID" width="120">
                              </vxe-table-column> -->
                              <!-- <vxe-table-column field="req_itemcode" sortable title="申请项目代码" width="80"></vxe-table-column> -->
                              <vxe-table-column field="feeitemcode" sortable title="收费项目代码" width="80"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </div>
              </rm-layout-right>
          </rm-layout-left>
      </div>

      <el-dialog v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="headtitle" :visible.sync="dialogVisible">
          <rm-pop-common ref="popcom" @change="popcomchange" @cancel="dialogVisible=false;" :datatype="datatype"></rm-pop-common>
      </el-dialog>

      <el-dialog :visible.sync="dialogFinshReport" @close="dialogFinshReportclose" ref="qweqweqwe" title="报告项目选择" width="642px" v-el-drag-dialog :close-on-click-modal="false">
          <vxe-toolbar style="margin-bottom:5px;">
              <template v-slot:buttons>
                  <el-input-number size="small" style="max-width:150px;" v-model="timespan" @keyup.enter.native="QueryDurationFinishReport"></el-input-number>天内报告数据
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <el-button @click="QueryDurationFinishReport" icon="el-icon-search" size="small" slot="append" type="primary">查询</el-button>
                  <el-button @click="dialogFinshReportclose" icon="el-icon-close" size="small" slot="append">退出</el-button>
              </template>
          </vxe-toolbar>
          <vxe-table :data.sync="FinshReportData" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="300" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable show-overflow size="mini" stripe header-align="center">
              <vxe-table-column field="sampledate" sortable title="标本日期" width="80" :formatter="['toDateString', 'yyyy-MM-dd']"></vxe-table-column>
              <vxe-table-column field="sampleno" sortable title="标本号" width="60"></vxe-table-column>
              <vxe-table-column field="ischk" sortable title="选择" width="40" align="center">
                  <template v-slot="{row}">
                      <el-checkbox v-model="row.ischk" true-label="1" false-label="0" :disabled="row.chkflag=='0'" @change="FinshReportChk(row)"></el-checkbox>
                  </template>
              </vxe-table-column>
              <vxe-table-column field="itemcode_en" sortable title="英文缩写" width="70"></vxe-table-column>
              <vxe-table-column field="rpt_itemname" sortable title="项目名称" width="110"></vxe-table-column>
              <vxe-table-column field="result_str" sortable title="检验结果" width="70"></vxe-table-column>
              <vxe-table-column field="rptunitname" sortable title="报告单元" width="110"></vxe-table-column>
          </vxe-table>
      </el-dialog>

  </div>
</template>

<script>
import { Promise } from "q";
import { log } from "util";
import { max } from "moment";
import XE from "xe-utils"; //引入工具类
export default {
  name: "MNG234",
  data() {
      return {
          //全局
          sumprice: 0,
          middle_center: 405,
          pagekey: 0,
          copyflag: 0,
          buttonwidth: "",
          groupname: "分单类别",
          grouptype: "reqgroup",
          show_right: false, //外部代码模式
          show_remind: false, //删除对照不提醒
          reqgroup_model: "", //项目分单类别
          rptunit_model: "", //报告所属单元select model
          rptitemclass_model: "", //报告项目类别 select model;
          ////////  req_item_dict 申请项目 数据变量声明  /////////
          item_dict_loading: false,
          item_dict_tableData: [], //req_item_dict 表数据容器(界面展示)
          item_dict_currentRow: [], //req_item_dict 点击数据行获取数据容器
          item_dict_seachKey: "", //查询条件
          ////////  lab_reqitem_rptitem 对应表 数据变量声明  //////////
          reqitem_feeitem_loading: false,
          reqitem_feeitem_tableData: [],
          stickdata: [],
          copydatalen: 0,
          dialogdetail: false,
          detailData: [],
          reqitem_rptitem_delBtnbool: true,
          reqitem_feeitem_saveBtnbool: true,
          externalcode_tableData: [], //界面展示数据
          externalcode_tableDataLog: [], //AJAX真实获取数据
          externalcode_seach: "", //外部代码查询条件
          dialogTable_externalcode: false, //外部代码弹出框控制标志
          externalcode_rowIndex: "", //打开外部代码弹出框 记录行号
          externalcode_flag: "", //打开外部代码弹出框 记录外部代码 1/2/3
          ////////  feeitem 对应表 数据变量声明  //////////
          feeitem_loading: false,
          feeitem_tableData: [], //lab_rptitem 表数据容器(界面展示)
          feeitem_seachKey: "", //查询条件
          okFirstLoading: false,
          HospitalOptions: [],
          utype: this.$tool.getSession(this.$tool.loginutype),
          dialogFinshReport: false,
          dialogVisible: false,
          timespan: 10,
          FinshReportData: [],
          RowDetail: [],
          rptunitidoption: [],
          specimen_codeoption: [],
          datatype: "",
          headtitle: "",
          poprow_specimen: [],
          isbis: false,
      };
  },
  created() {
      this.isbis = this.$tool.checkBis();
      this.ddlInitdata();
      this.initOption();
      this.item_dict_refresh();
      this.feeitem_refresh();
      this.rexternalmode_refresh();
  },
  mounted() { },
  updated() {
      this.getButtonWidth();
      if (this.okFirstLoading) {
          let currentrow = this.$refs.item_dict_Table.getData(0);
          if (currentrow) {
              this.$nextTick(() => {
                  this.okFirstLoading = false;
                  this.$refs.item_dict_Table.setCurrentRow(currentrow);
                  this.item_dict_currentChangeEventFun(currentrow);
              });
          }
      }
  },
  methods: {
      initOption() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "initOption",
                  },
              })
              .then((res) => {
                  this.rptunitidoption = res.dt2;
                  this.specimen_codeoption = res.dt1;
              });
      },
      ddlInitdata() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG215",
                  method: "post",
                  data: {
                      action: "ddlInitialList",
                  },
              })
              .then((response) => {
                  this.HospitalOptions = response;
              });
      },
      cellactiveMethod({ row, column }) {
          if (["externalcode1", "externalcode2", "externalcode3"].indexOf(column.property) > -1) {
              return true;
          } else {
              return false;
          }
      },
      /////////////////////////////////////   全局    /////////////////////////////////////////////
      //控制el-col 宽度
      col_show_hide() {
          //this.show_right = !this.show_right;
          if (this.show_right) {
              this.middle_center = 0;
          } else {
              this.middle_center = 405;
          }
          this.pagekey++;
      },
      //删除对照不提醒
      col_del_remind() {
          this.show_remind == false ? true : false;
      },
      //select 数据变化事件集合
      all_selectChange_event(evt, flag) {
          if (flag === "el_group") {
              this.item_dict_refresh();
          }
          if (flag === "el_unit") {
              this.feeitem_refresh();
          }
          if (flag === "el_rptitemclass") {
              this.feeitem_refresh();
          }
      },
      getButtonWidth() {
          if (this.$refs.buttondiv) {
              this.buttonwidth = this.$refs.buttondiv.parentElement.parentElement.parentElement.parentElement.offsetWidth - 200 + "px";
          }
      },
      //清空条件
      all_clear() {
          this.reqgroup_model = "";
          this.rptunit_model = "";
          this.rptitemclass_model = "";
          this.item_dict_seachKey = "";
          this.feeitem_seachKey = "";
          this.item_dict_refresh();
          this.feeitem_refresh();
      },
      /////////////////////////////////////   req_item_dict   /////////////////////////////////////////////
      //req_item_dict数据获取/刷新方法 AJAX
      item_dict_refresh() {
          this.item_dict_loading = true;
          let _this = this;
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "item_dict_query",
                      selectkey: _this.item_dict_seachKey.trim(" "),
                      groupid: _this.reqgroup_model,
                  },
              })
              .then((res) => {
                  this.item_dict_tableData = res.Data;
                  this.item_dict_loading = false;
                  this.okFirstLoading = true;
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      item_dict_syncdata() {
          this.item_dict_tableData.forEach(x => {
              x.operation = this.syncdata(x);
          });
      },
      async syncdata(item) {
          try {
              const res = await this.$tool.request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "syncdata",
                      req_itemcode: item.req_itemcode,
                      req_itemname: item.req_itemname,
                      his_itemcode: item.his_itemcode,
                  }
              });
              item.operation = res.errcode;
          } catch (e) {
              this.$message.warning(e);
          }
      },
      item_dict_rowclassname({ row }) {
          if (row.operation == '1')
              return "row-blue";
          if (row.operation == '-1')
              return "row-red";
      },
      //req_item_dict 数据表格 行获取事件
      item_dict_currentChangeEvent({ row }) {
          this.item_dict_currentChangeEventFun(row);
      },
      dialogFinshReportclose() {
          this.dialogFinshReport = false;
      },
      //双击开窗
      async showDurationFinishReport({ row, column }) {
          if (column.property == "req_itemname") {
              this.timespan = 10;
              this.QueryDurationFinishReport();
          } else if (column.property == "specimenname") {
              this.poprow_specimen = row;
              this.datatype = "specimen";
              this.headtitle = "标本类型";
              this.dialogVisible = true;
          }
      },
      async QueryDurationFinishReport() {
          try {
              const res = await this.$tool.request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  timeout: 600000,
                  data: {
                      action: "QueryDurationFinishReport",
                      req_itemcode: this.item_dict_currentRow.req_itemcode,
                      timespan: this.timespan,
                  },
              });
              this.FinshReportData = res.data;
              this.dialogFinshReport = true;
          } catch (e) {
              this.$alert(e, "信息");
          }
      },
      item_dict_currentChangeEventFun(row) {
          this.item_dict_currentRow = row;
          this.reqitem_feeitem_refresh(); //获取对照关系表
      },
      ////////////////////////////////////    lab_reqitem_rptitem   //////////////////////////////////////////////
      //lab_reqitem_rptitem 数据获取/刷新方法 AJAX
      reqitem_feeitem_refresh() {
          this.reqitem_feeitem_loading = true;
          this.sumprice = 0;
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "reqitem_feeitem_query",
                      req_itemcode: this.item_dict_currentRow.req_itemcode,
                  },
              })
              .then((res) => {
                  this.reqitem_feeitem_tableData = res.Data;
                  this.reqitem_feeitem_tableData.forEach((item) => {
                      this.sumprice += item.item_price * item.qty;
                  })
                  this.reqitem_feeitem_loading = false;
                  this.reqitem_feeitem_dataChanged();
              })
              .catch((e) => {
                  console.log("erro", e);
              });
      },
      //externalcode_refresh 数据获取/刷新方法
      rexternalmode_refresh() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "get_externalmode",
                  },
              })
              .then((res) => {
                  this.externalcode_tableDataLog = res.Data;
                  this.externalcode_tableData = JSON.parse(JSON.stringify(res.Data[0]));
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },

      //lab_reqitem_rptitem 删除
      rptitem_delete_Eevent(delrow) {
          if (this.$ddldata.IsAreaMode && this.utype != "G" && this.item_dict_currentRow.hospcode == "All") {
              this.$alert("您不是管理员，不能对医院代码为All对应的数据做删除！", "提示", {
                  confirmButtonText: "确定",
              });
              return false;
          }
          if (delrow) {
              if (!this.show_remind) {
                  //提醒
                  this.$confirm("此操作将删除选中的数据, 是否继续?", "提示", {
                      confirmButtonText: "确定",
                      cancelButtonText: "取消",
                      type: "warning",
                  })
                      .then(() => {
                          //删除
                          // this.$refs.reqitem_feeitem_table.removeSelecteds();
                          this.delRecordsSave("", delrow);
                      })
                      .catch(() => { });
              } else {
                  //不提醒
                  //this.$refs.reqitem_feeitem_table.removeSelecteds();
                  this.delRecordsSave("", delrow);
              }
          }
      },
      delRecordsSave(addrow, delrow) {
          this.save(addrow, delrow).then((res) => {
              if (res == "1") {
                  this.$message({
                      message: "删除成功！",
                      type: "success",
                      duration: "1000",
                  });
                  this.reqitem_feeitem_refresh();
              } else {
                  this.$message.error("删除失败！" + res);
              }
          });
      },
      reqitem_feeitem_dblclick({ row, rowIndex, columnindex, column }) {
          if (["feeitemname", "seq", "req_itemname", "feeitemcode", 'item_price', 'synctime'].includes(column.property)) {
              this.rptitem_delete_Eevent(row);
          }
      },
      //保存数据 保存
      reqitem_feeitem_SaveEvent() {
          if (this.$ddldata.IsAreaMode && this.utype != "G" && this.item_dict_currentRow.hospcode == "All") {
              this.$alert("您不是管理员，不能对医院代码为All对应的数据做保存！", "提示", {
                  confirmButtonText: "确定",
              });
              return false;
          }

          let Alldata = this.$refs.reqitem_feeitem_table.getRecordset();
          let GetDelData = Alldata.removeRecords;
          let GetUpData = Alldata.updateRecords;
          let insertRecords = Alldata.insertRecords;
          if ((GetDelData == undefined || GetDelData.length <= 0) && (GetUpData == undefined || GetUpData.length <= 0) && (insertRecords == undefined || insertRecords.length <= 0)) {
              this.$message({
                  message: "数据未发生变化！",
                  type: "warning",
              });
              return false;
          }
          //存入数据库
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "reqitem_feeitem_save",
                      delData: GetDelData,
                      upData: GetUpData,
                      insertData: insertRecords,
                      price: this.sumprice
                  },
              })
              .then((res) => {
                  //刷新对应表
                  if (res == "1") {
                      this.$pub.message(this, "保存成功！", "success");
                      this.reqitem_feeitem_refresh();
                  } else {
                      this.$message.error("保存失败！" + res);
                  }
              })
              .catch((e) => {
                  this.$message.error(e);
              });
      },
      //lab_reqitem_feeitem 数据变化事件
      reqitem_feeitem_dataChanged() {
          if (this.reqitem_feeitem_tableData.length == 0) {
              this.reqitem_feeitem_saveBtnbool = true;
          } else {
              this.reqitem_feeitem_saveBtnbool = false;
          }
      },
      //可选check改变
      reqitem_rptitem_column_OptionalChange(rowIndex) {
          this.reqitem_feeitem_SaveEvent();
      },
      //标本或类型相关check改变
      reqitem_rptitem_column_usedetailChange(row) {
          if (row.usedetail == "1") {
              this.reqitem_feeitem_SaveEvent();
          } else {
              this.$confirm("取消相关将删除相关数据，你确定取消吗？", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              })
                  .then(() => {
                      this.$tool
                          .request({
                              url: "MNG/MNG2/MNG234",
                              method: "post",
                              data: {
                                  action: "delreqitem_rptitem_detail",
                                  reqitemcode: row.req_itemcode,
                                  rptitemcode: row.rpt_itemcode,
                              },
                          })
                          .then((res) => {
                              this.reqitem_feeitem_SaveEvent();
                          })
                          .catch((e) => {
                              this.$message.error(e);
                          });
                  })
                  .catch(() => {
                      row.usedetail = "1";
                  });
          }
      },
      //lab_rptitem数据获取/刷新方法 AJAX
      feeitem_refresh() {
          this.$nextTick(() => {
              this.feeitem_loading = true;
              let _this = this;
              this.$tool
                  .request({
                      url: "MNG/MNG2/MNG234",
                      method: "post",
                      data: {
                          action: "feeitem_query",
                          selectkey: _this.feeitem_seachKey.trim(" "),
                      },
                  })
                  .then((res) => {
                      this.feeitem_tableData = res.Data;
                      this.feeitem_loading = false;
                  })
                  .catch((e) => {
                      this.$message.error(e);
                  });
          });
      },
      //lab_rptitem 数据表格 行获取事件 右边
      feeitem_add_Eevent({ row, rowIndex, column, columnIndex }, event) {
          if (this.item_dict_currentRow == undefined || this.item_dict_currentRow.length <= 0) {
              this.$message({
                  message: "请先确认申请项目！",
                  type: "warning",
              });
              return false;
          }
          if (this.$ddldata.IsAreaMode && this.utype != "G" && this.item_dict_currentRow.hospcode == "All") {
              this.$alert("您不是管理员，不能对医院代码为All的数据做对照！", "提示", {
                  confirmButtonText: "确定",
              });
              return false;
          }

          this.AddReqItem_FeeItem(row);
      },
      AddReqItem_FeeItem(row) {
          let data = this.$refs.reqitem_feeitem_table.tableData;
          let fdata = data.filter((item) => item.feeitemcode == row.feeitemcode);
          if (fdata.length > 0) {
              this.$message.warning("该报告项目已存在！");
              return false;
          }
          let seqlist = XE.max(data, (item) => item.seq);
          let maxseq = 10;
          if (!!seqlist) {
              maxseq = seqlist.seq + 10;
          }

          let add_reqitem_rptitem_custom = {
              feeitemname: row.feeitemname,
              seq: maxseq,
              req_itemcode: this.item_dict_currentRow.req_itemcode,
              feeitemcode: row.feeitemcode,
              qty: 1
          };

          // this.$refs.reqitem_feeitem_table.insert(add_reqitem_rptitem_custom);
          this.save(add_reqitem_rptitem_custom, "").then((res) => {
              if (res == "1") {
                  this.$message({
                      message: "保存成功！",
                      type: "success",
                      duration: "1000",
                  });
                  this.reqitem_feeitem_refresh();
              } else {
                  this.$message.error("保存失败！" + res);
              }
          });
      },
      async save(insertRecord, DelRecord) {
          try {
              const res = await this.$tool.request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "reqitem_feeitem_save",
                      delData: !DelRecord ? [] : [DelRecord],
                      upData: [],
                      insertData: !insertRecord ? [] : [insertRecord],
                  },
              });
              return res;
          } catch (e) {
              console.log(e);
          }
      },
      //"rm-cancel"; //作废
      //"rm-disable"; //禁用
      //"rm-readonly"; //只读
      //"rm-alert"; //警告
      rpt_req_rowclassname({ row, rowIndex }) {
          if (row.optional == "1") {
              return "col-red"; //禁用
          } else {
              return "";
          }
      },
      Copy() {
          this.copydata = JSON.parse(JSON.stringify(this.reqitem_feeitem_tableData));
      },
      Stick() {
          if (this.item_dict_currentRow == undefined || this.item_dict_currentRow.length <= 0) {
              this.$message({
                  message: "请先确认申请项目！",
                  type: "warning",
              });
              return false;
          }

          var maxseq = 0;
          var insertRecords = this.$refs.reqitem_feeitem_table.getInsertRecords();
          if (insertRecords.length > 0) {
              //后添加的数据中遍历最大SEQ
              maxseq = Number(insertRecords[0].seq);
          } else {
              if (this.reqitem_feeitem_tableData.length > 0) {
                  //数据库中数据遍历最大SEQ
                  maxseq = Number(this.reqitem_feeitem_tableData[this.reqitem_feeitem_tableData.length - 1].seq);
              }
          }
          for (var j = 0; j < this.copydata.length; j++) {
              if (insertRecords.filter((m) => m.rpt_itemcode == this.copydata[j].rpt_itemcode).length > 0) {
                  continue;
              }
              if (this.reqitem_feeitem_tableData.filter((m) => m.rpt_itemcode == this.copydata[j].rpt_itemcode).length > 0) {
                  continue;
              }
              this.copydata[j].req_itemcode = this.item_dict_currentRow.req_itemcode;
              this.copydata[j].seq = maxseq + 10;
              maxseq = this.copydata[j].seq;
              this.$refs.reqitem_feeitem_table.insert(this.copydata[j]);
          }
          this.reqitem_feeitem_SaveEvent();
      },

      dialogbtnDel() {
          try {
              this.$confirm("您确定删除这条数据吗？", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
              })
                  .then(() => {
                      var delrow = this.$refs.detailXtable.getCurrentRow();
                      if (delrow) {
                          var alld = this.$refs.detailXtable.tableData;
                          var rowindex = alld.indexOf(delrow);
                          this.$refs.detailXtable.remove(delrow);
                          this.exesave("D").then((res) => {
                              if (res.errcode == "1") {
                                  this.$pub.message(this, "删除成功！", "success");
                                  let havedata = this.$refs.detailXtable.tableData;
                                  this.reqitem_feeitem_refresh();
                                  if (havedata.length > 0) {
                                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                                      let selectrow = havedata[rowindex];
                                      this.$refs.detailXtable.setCurrentRow(selectrow);
                                  } else {
                                      this.$refs.detailXtable.setCurrentRow(null);
                                  }
                              }
                          });
                      }
                  })
                  .catch(() => { });
          } catch (e) {
              console.log("error", e);
          }
      },

      async exesave(op) {
          try {
              let data = this.$refs.detailXtable.tableData;
              if (op == "S") {
                  let kdata = [];
                  let key = "";
                  data.forEach((element) => {
                      let key = element.specimen_code + "$" + element.rptunitid;
                      kdata.push(key);
                  });

                  let kdata2 = XE.uniq(kdata);
                  if (kdata2.length != kdata.length) {
                      this.$alert("数据中不能重复保存相同的标本类型和报告单元！", "信息");
                      return false;
                  }
              }

              const res = await this.$tool.request({
                  url: "MNG/MNG2/MNG234",
                  method: "post",
                  data: {
                      action: "savedetail",
                      savinfo: this.$refs.detailXtable.getRecordset(),
                  },
              });
              return res;
          } catch (e) {
              this.$alert(e, "信息");
          }
      },
      isRepeat(arr) {
          var hash = {};
          for (var i in arr) {
              if (hash[arr[i]]) {
                  return true;
              }
              // 不存在该元素，则赋值为true，可以赋任意值，相应的修改if判断条件即可
              hash[arr[i]] = true;
          }
          return false;
      },
      async savedetail() {
          try {
              const res = await this.exesave("S");
              if (res) {
                  if (res.errcode == "1") {
                      this.$pub.message(this, "保存成功！", "success");
                      this.dialogdetail = false;
                      this.reqitem_feeitem_refresh();
                  } else {
                      this.$alert("保存失败！" + res.errmsg);
                  }
              }
          } catch (e) {
              this.$alert(e, "信息");
          }
      },
      popcomchange(code, name) {
          this.poprow_specimen.specimen_code = code;
          this.poprow_specimen.specimenname = name;
          this.dialogVisible = false;
      },
  },
};
</script>

<style scoped>
.pagetop {
  left: 0;
  right: 0;
  height: 35px;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
}

.pagecenter {
  position: absolute;
  top: 40px;
  width: 100%;
  left: 0;
  bottom: 5px;
  overflow: auto;
}

.middle-left {
  position: absolute;
  top: 0px;
  bottom: 0px;
  width: 400px;
  left: 0px;
}

.middle-right {
  position: absolute;
  top: 0px;
  bottom: 0px;
  width: 400px;
  right: 0px;
}
.child_exteral {
  height: 100%;
  width: 400px;
  position: relative;
}
.child_bottom {
  position: absolute;
  top: 33px;
  width: 100%;
  bottom: 0px;
}
/deep/ .vxe-table .vxe-body--row.col-red {
  color: red;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table tr td:nth-child(1) {
  width: 80px;
}
table {
  font-size: 12px;
}

.table1style tr td {
  padding: 0px 2px 0px 5px;
}

.el-input-number--small {
  width: 130px;
  line-height: 23px;
}
/deep/ .vxe-body--row.row-blue {
  color: blue !important;
  font-weight: bold;
}
/deep/ .vxe-body--row.row-red {
  color: red !important;
  font-weight: bold;
}
</style>